#include "DDCPItemTypesTest.hpp"
#include "DDCPTestCfg.hpp"

#define TEST_ENUM(_enum, _name) _enum
#define TEST_TYPE(_type, _name) _type
#define TEST_NAME(_type, _name) _name

enum TestType{
    TEST_ENUM(ACTION, "Action"),
    TEST_ENUM(CONTROL, "Control"),
    TEST_ENUM(QUERY, "Query"),
    TEST_ENUM(NOTIFY, "Notify"),
    TEST_ENUM(RESPONSE, "Response"),
    TEST_ENUM(CNTRLRESP, "ControlResponse"),
    TEST_ENUM(QUERYRESP, "QueryResponse"),
    MAXTESTTYPE
};


int TestTypeArray[] = {
    TEST_TYPE(ACTION, "Action"),
    TEST_TYPE(CONTROL, "Control"),
    TEST_TYPE(QUERY, "Query"),
    TEST_TYPE(NOTIFY, "Notify"),
    TEST_TYPE(RESPONSE, "Response"),
    TEST_TYPE(CNTRLRESP, "ControlResponse"),
    TEST_TYPE(QUERYRESP, "QueryResponse")
};

const char* TestNameArray[] ={
    TEST_NAME(ACTION, "Action"),
    TEST_NAME(CONTROL, "Control"),
    TEST_NAME(QUERY, "Query"),
    TEST_NAME(NOTIFY, "Notify"),
    TEST_NAME(RESPONSE, "Response"),
    TEST_NAME(CNTRLRESP, "ControlResponse"),
    TEST_NAME(QUERYRESP, "QueryResponse")
};

void CDDCPItemTypesTest::test(){
    testGet();
    testGetType();
}


void CDDCPItemTypesTest::testGet(){
    CDDCPItemTypes testType;

    for (int i = -10; i < 20; i++){
        const char* tchar = testType.get((CDDCPItemTypes::EDDCPType)i);
        if (0 <= i && i < MAXTESTTYPE){
            if (0 != strcmp(tchar, TestNameArray[i])){
                ERROR_LOGING("CDDCPItemTypes::get()", i);
            }
        } else{
            if (!tchar){
                ERROR_LOGING("CDDCPItemTypes::get()", i);
            }
        }
    }
    return;
}

void CDDCPItemTypesTest::testGetType(){
    CDDCPItemTypes testType;

    for (int i = 0; i < MAXTESTTYPE; i++){
        const char* tchar = TestNameArray[i];
        int iType = testType.getType(tchar);
        if (iType != i){
            ERROR_LOGING("CDDCPItemTypes::getType()", tchar);
        }
    }
    const char* RandomArray[] = {"Hello", "World", "This", "Function", "I", "s", "Working", NULL};
    for (int i = 0; RandomArray[i]; i++){
        int iType = testType.getType(RandomArray[i]);
        if (iType != -1){
            ERROR_LOGING("CDDCPItemTypes::getType()", RandomArray[i]);
        }
    }
    int iType = testType.getType(NULL);
    if (iType != -1){
        ERROR_LOGING("CDDCPItemTypes::getType()", "NULL");
    }
    return;
}

